package com.xc.pattern.memento;

/**
 * @author xingchen
 * @description
 * @create 2022-09-11 21:51
 */
public class RoleOriginator {

    /**
     * 生命力
     */
    private int live = 100;


    /**
     * 攻击力，会上涨
     */
    private int attack = 50;

    public int getLive() {
        return live;
    }

    public void setLive(int live) {
        this.live = live;
    }

    public int getAttack() {
        return attack;
    }

    public void setAttack(int attack) {
        this.attack = attack;
    }

    public void display() {
        System.out.println("开始===========");
        System.out.println("生命力:" + live);
        System.out.println("攻击力:" + attack);
        System.out.println("结束===========");
    }


    public void fight() {
        //攻击力会上涨
        this.attack = attack + 2;
        this.live = live - 10;
    }


    /**
     * 保存快照，存储状态
     *
     * @return
     */
    public RoleStateMemento saveState() {
        return new RoleStateMemento(live, attack);
    }

    /**
     * 恢复
     *
     * @param memento
     */
    public void recovery(RoleStateMemento memento) {
        this.attack = memento.getAttack();
        this.live = memento.getLive();
    }


}
